package com.wujilee.wujileejuc.juc02join;

/**
 * @author liwuji
 * @date 2024/6/21
 * @desc
 **/
public class Demo {
   public static void main(String[] args) throws InterruptedException {
      demo1();
      
   }
   private static void demo() throws InterruptedException {
      Thread thread = new Thread(() -> {
         try {
            Thread.sleep(100L);
         } catch (InterruptedException e) {
            throw new RuntimeException(e);
         }
         System.out.println("join 执行");
      });
      Thread thread1 = new Thread(() -> {
         System.out.println("1");
      });
      thread1.start();
      thread.start();

      // join执行之后 调用者后面的代码会等待被调用执行完再执行
      thread.join();
      System.out.println("11");
   }

   /**
    * 中断标志位的情况
    * @throws InterruptedException
    */
   private static void demo1() throws InterruptedException {
      Thread thread = new Thread(() -> {
         try {
            System.out.println("没有打断之前的标志位 "+Thread.currentThread().isInterrupted());
            
            System.out.println("111");
            Thread.sleep(1000L);
         } catch (InterruptedException e) {
            System.out.println("当前的标志位 "+Thread.currentThread().isInterrupted());
            throw new RuntimeException(e);
         }
         System.out.println("join 执行");
      });
      Thread thread1 = new Thread(() -> {
         try {
            thread.join();
            System.out.println("1111");
         } catch (InterruptedException e) {
            System.out.println("父线程的标志位"+Thread.currentThread().isInterrupted());
            throw new RuntimeException(e);
         }
      });
      thread1.start();
      thread.start();
      thread.interrupt();

      while (true){
         
      }
   }
}
